<?php

namespace App\Models\GameTool;

use App\Models\Admin;
use App\Models\Config\Channels;
use App\Models\Config\Games;
use App\Models\Config\Servers;
use Illuminate\Database\Eloquent\Model;
use Jenssegers\Mongodb\Eloquent\HybridRelations;

class GameRecharge extends Model
{
    use HybridRelations;//mysql mongodb混合关系

    protected $connection = 'mysql';
    //字段白名单
    protected $fillable = [];
    //字段黑名单
    protected $guarded = ['goBackUrl'];
    //表名
    protected $table = 'mc_game_recharge';

    public function approver()
    {
        return $this->hasOne(Admin::class, 'id', 'approver_admin_id');
    }

    public function game()
    {
        return $this->hasOne(Games::class, 'game_id', 'game_id');
    }

    public function channel()
    {
        return $this->hasOne(Channels::class, 'channel_id', 'channel_id')->where('game_id', '=', session('game_id'));
    }

    public function server()
    {
        return $this->hasOne(Servers::class, 'server_id', 'server_id')
            ->where('game_id', '=', strval(session('game_id')))
            ->where('channel_id', '=', strval($this->channel_id));
    }
}
